//
//  Person.m
//  OC_02实例变量可见度_方法
//
//  Created by wyx on 16/2/25.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Person.h"

@implementation Person
#pragma mark - setter&&getter
- (void)setName:(NSString *)name{
    _name = name;
}
-(NSString *)name{
    return _name;
}
#pragma mark - other
- (void) name:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    _name = name;
    _sex = sex;
    _age = age;
}
- (void) sayHi{
    NSLog(@"name: %@, sex:%@, age:%ld",_name,_sex,_age);
}
#pragma mark - 自定义初始化方法
- (instancetype)initWithName:(NSString *)name{
    self = [super init];
    if (self) {
        _name = name;
    }
    return self;
}
- (instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    self = [super init];
    if (self) {
        _name = name;
        _sex = sex;
        _age =age;
    }
    return self;
}
#pragma mark - 重写 init
- (instancetype)init{
   //1.调用父类 init 方法
    self = [super init];//self 指对象本身
    //加判断条件,当 self 指针不为空时,再赋值
    if (self) {
        //2.给某些实例赋值.
        _age = 20;
    }
    return self;
}
#pragma mark - 构造器
+ (instancetype)person{
    //1.alloc init
    Person *per = [[Person alloc] init];
    //2.返回创建出来的对象
    return per;
}
+ (instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    Person *per = [[Person alloc] initWithName:name sex:sex age:age];
    //实例变量赋值
    //[per setName:name];
    return per;
    
}


@end
